﻿using RedisInAction;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Text;
using System.Threading.Tasks;

namespace Demo
{
    public class TestGeneration
    {
        public static void TestNO1()
        {
            SysNoConfig config = new SysNoConfig();
            config.fcode = "A0001";
            config.fprefix = "AO";
            config.fserialdate = Serialdate.yyMMdd.ToString();
            config.fseriallength = 7;
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(GenerationNO.GetNO(config));
            }
        }

        public static void TestNO2()
        {
            SysNoConfig config = new SysNoConfig();
            config.fcode = "A0002";
            config.fprefix = "BO";
            config.fseriallength = 7;
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(GenerationNO.GetNO(config));
            }
        }

        public static void TestNO3()
        {
            SysNoConfig config = new SysNoConfig();
            config.fcode = "A0002";
            config.fprefix = "CO";
            config.fseriallength = 7;
            config.frandomlength = 3;
            for (int i = 0; i < 5; i++)
            {
                Console.WriteLine(GenerationNO.GetNO(config));
            }
        }

        public static void TestNO4()
        {
            SysNoConfig config = new SysNoConfig();
            config.fcode = "A0002";
            config.fprefix = "DO";
            config.fserialdate = Serialdate.yyMMdd.ToString();
            config.fseriallength = 7;
            config.frandomlength = 1;
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < 10000; i++)
            {
                GenerationNO.GetNO(config);
            }
            stopwatch.Stop();
            Console.WriteLine($"生成10000单耗时{stopwatch.ElapsedMilliseconds}");
        }

        public static void TestNO5()
        {
            List<Task> list = new List<Task>();
            Stopwatch stopwatch = new Stopwatch();
            stopwatch.Start();
            for (int i = 0; i < 5; i++)
            {
                list.Add(Task.Run(TestNO4));
            }
            Task.WaitAll(list.ToArray());
            stopwatch.Stop();
            Console.WriteLine($"多线程生成10000单耗时{stopwatch.ElapsedMilliseconds}");
        }
    }
}
